#include "proxydlg.h"
#include "ui_proxydlg.h"

ProxyDlg::ProxyDlg(QWidget *parent) : QDialog(parent)
{
    setupUi(this);
    enableProxy->setChecked(settings.settings.ProxyEnable());
    proxyOptions->setEnabled(settings.settings.ProxyEnable());

    hostEdit->setText(settings.settings.ProxyHost());
    portEdit->setValue(settings.settings.ProxyPort());
    userEdit->setText(settings.settings.ProxyUser());
    passEdit->setText(settings.settings.ProxyPass());
}

void ProxyDlg::saveSettings()
{
    settings.settings.setProxyEnable(bool(enableProxy->isChecked()));
    settings.settings.setProxyHost(hostEdit->text());
    settings.settings.setProxyPort(portEdit->value());
    settings.settings.setProxyUser(userEdit->text());
    settings.settings.setProxyPass(passEdit->text());
    settings.save();
    settings.applyProxySettings();
}

void ProxyDlg::accept()
{
    saveSettings();
    QDialog::accept();
}

ProxyDlg::~ProxyDlg()
{
    delete ui;
}
